<extend name="Public/base"/>

<block name="body">
  <div class="main-title">
    <h2>
      <eq name="item_id" value="0">
      商品销量一览表
      <else/>
      <i class="text-success">{$item_id|get_item_name}</i> 销量统计
      </eq>
    </h2>
  </div>

  <!-- 按钮工具栏 -->
  <div class="cf">
    <div class="fl">
      <eq name="item_id" value="0">
      <a class="btn" target="_blank" href="{:U('',array('export' => 1, 'sort' => I('get.sort'), 'start_time' => I('get.start_time'), 'end_time' => I('get.end_time')))}">导出</a>
      </eq>
      <a class="btn" href="{:U()}">刷 新</a>（点击"刷新"按钮清除搜索条件，显示全部信息。）
    </div>

    <!-- 高级搜索 -->
    <form action="{:U()}" method="GET" id="J_search_form">
    <div class="search-form fr cf">
      <eq name="item_id" value="0">
      <div class="fl">
        <select name="sort">
          <option value="desc">销量倒序</option>
          <option value="asc">销量正序</option>
        </select>
      </div>
      </eq>
      <div class="sleft">
        
        <input type="text" name="start_time" class="search-input w-100 date_select" value="{$start_time}" placeholder="起始时间"/>
        <span class="fl line-h">至</span>
        <input type="text" name="end_time" class="search-input w-100 date_select" value="{$end_time}" placeholder="今天"/>
      </div>
      <div class="sleft">
        <input type="text" name="item_id" id="item_id" class="search-input w-100" value="{:I('get.item_id')}" placeholder="商品ID"/>
        <a class="sch-btn" href="javascript:;" id="J_search"><i class="btn-search"></i></a>
      </div>
    </div>
    </form>
  </div>
  <!-- 数据表格 -->
  <div class="data-table table-striped">
    <table>
      <thead>
        <tr>
          <th width="80">商品ID</th>
          <th>商品编号</th>
          <th>商品类别</th>
          <th>商品名称</th>
          <th>销量（件）</th>
          <eq name="item_id" value="0">
          <th width="100">操作</th>
          </eq>
        </tr>
      </thead>
      <tbody id="lists">
        <volist name="stat.lists" id="vo">
          <tr>
            <td>{$vo.id}</td>
            <td><a href="{:U('/Item/detail?id='.$vo['id'])}" target="_blank" title="点击商品信息">{$vo.number}</a></td>
            <td>{$vo.category}</td>
            <td><a href="javascript:;" onclick="$('#item_id').val({$vo.id});$('#J_search_form').submit();">{$vo.name}</a></td>
            <td>{$vo.buynum}</td>
            <eq name="item_id" value="0">
            <td><a href="javascript:;" onclick="$('#item_id').val({$vo.id});$('#J_search_form').submit();">查看详情</a></td>
            </eq>
          </tr>
        </volist>
      </tbody>
    </table>
  </div>
  <div class="page">
    <ul>
      <li id="page"></li>
    </ul>
  </div>
  
  <gt name="item_id" value="0">
  <div class="main-title">
    <h2>
      销售明细
    </h2>
  </div>
  <!-- 数据表格 -->
  <div class="data-table table-striped">
    <table>
      <thead>
        <tr>
          <th>订单编号</th>
          <th>购买用户</th>
          <th>购买数量（件）</th>
          <th>收货人</th>
          <th>收货电话</th>
          <th>下单日期</th>
          <th>操作</th>
        </tr>
      </thead>
      <tbody>
      <notempty name="record_list">
        <volist name="record_list" id="vo">
          <tr>
            <td><a href="{:U('Order/view?id='.$vo['id'])}" target="_blank">{$vo.order_sn}</a></td>
            <td>{$vo.uid|get_nickname}</td>
            <td>{$vo.number}</td>
            <td>{$vo.ship.ship_uname}</td>
            <td>{$vo.ship.ship_mobile}</td>
            <td>{:date('Y-m-d', $vo['create_time'])}</td>
            <td><a href="{:U('Order/view?order_sn='.$vo['order_sn'])}" target="_blank">查看订单</a></td>
          </tr>
        </volist>
        <else/>
        <tr>
          <td colspan="10">
            <div class="list-empty">当前时间区间无销售记录！</div>
          </td>
        </tr>
      </notempty>
      </tbody>
    </table>
  </div>
  <div class="page">
  {$_page}
  </div>
  </gt>
</block>

<block name="script"> 
  <script language="javascript" type="text/javascript" src="__JS__/My97Date/WdatePicker.js"></script>
  <script type="text/javascript">
    $(function() {
      //搜索
      $("#search").click(function() {
        var url = $(this).attr('url');
        var query = $('.search-form').find("select,input").serialize();
        query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g, '');
        query = query.replace(/^&/g, '');
        url += query ? ((url.indexOf('?') > - 1 ? '&' : '?') + query) : '';
        window.location.href = url;
      });
      //回车自动提交
      $('.search-form').find('input').keyup(function(event) {
        if(event.keyCode === 13) {
          $("#search").click();
        }
      });
      //导航高亮
      highlight_subnav("{:U('goods')}");
      $('.date_select').focus(function() {
        WdatePicker({skin: 'twoer', dateFmt: 'yyyy-MM-dd', maxDate: '%y-%M-%d'});
      });
      //结束日期智能化判断
      if($('input[name="end_time"]').val() === "{$today}"){
        $('input[name="end_time"]').val("");
      }
      Core.setValue('sort', '{:I('get.sort', 'desc')}');
    });  
  </script>
  <script type="text/javascript">
    var obj,j;
    var page=0;
    var nowPage=0;//当前页
    var listNum=15;//每页显示条数
    var PagesLen;//总页数
    var PageNum=9;//分页链接接数(10个)
    onload=function(){
      obj=document.getElementById("lists").getElementsByTagName("tr");
      j=obj.length
      PagesLen=Math.ceil(j/listNum);
      upPage(0)
    }
    function upPage(p){
      nowPage=p
      //内容变换
      for (var i=0;i<j;i++){
        obj[i].style.display="none"
      }
      for (var i=p*listNum;i<(p+1)*listNum;i++){
        if(obj[i])obj[i].style.display=""
      }
      if(PagesLen > 1){
        //分页链接变换
        strS='<a href="###" onclick="upPage(0)">首页</a>  ';
        var PageNum_2=PageNum%2==0?Math.ceil(PageNum/2)+1:Math.ceil(PageNum/2);
        var PageNum_3=PageNum%2==0?Math.ceil(PageNum/2):Math.ceil(PageNum/2)+1;
        var strC="",startPage,endPage;
        if (PageNum>=PagesLen) {
          startPage=0;
          endPage=PagesLen-1;
        }else if (nowPage<PageNum_2){ //首页
          startPage=0;endPage=PagesLen-1>PageNum?PageNum:PagesLen-1
        }else {
          startPage=nowPage+PageNum_3>=PagesLen?PagesLen-PageNum-1: nowPage-PageNum_2+1;
          var t=startPage+PageNum;
          endPage=t>PagesLen?PagesLen-1:t;
        }
        for (var i=startPage;i<=endPage;i++){
         if (i==nowPage){
           strC+='<a href="###" class="current" style="font-weight:700;" onclick="upPage('+i+')">'+(i+1)+'</a> ';
         }else {
           strC+='<a href="###" onclick="upPage('+i+')">'+(i+1)+'</a> '
         }
        }
        strE=' <a href="###" onclick="upPage('+(PagesLen-1)+')">尾页</a>  '
        strE2="<a>"+(nowPage+1)+"/"+PagesLen+"页"+"  共"+j+"条</a>"
        document.getElementById("page").innerHTML=strS+strC+strE+strE2;
      }
    }
  </script>
</block>